home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / DocShell / RlShlEv.cpp < prev    next >
Encoding:
Text File  |  1996-04-22  |  50.2 KB  |  1,734 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        RlShlEv.cpp
  3.  
  4.     Contains:    Apple Event handlers for the document shell.
  5.  
  6.     Owned by:    Eric House
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <63>    10/26/95    eeh        1296308: check for null draftToBringForward
  13.         <62>    10/12/95    eeh        1287143: handle activate events where
  14.                                     document isn't open
  15.         <61>     9/13/95    TÇ        1249149 FB2: Memory leak/crash fixes
  16.         <60>     9/11/95    NP        1272294: Messaging code cleanup.
  17.         <59>      9/8/95    TÇ        1282092 FB2: Shell must check nil after SOM
  18.                                     new
  19.         <58>      9/5/95    TÇ        FBs: 1266428, 1274419, 1274421, 1274423,
  20.                                     1274429, 1274435 Fixed the Shell to handle
  21.                                     multiple documents in a process. Needed for
  22.                                     CyberDog.
  23.         <57>     8/26/95    TÇ        1279063 FB3:  must check results of SOM
  24.                                     operator new
  25.         <56>     8/25/95    JP        1272288: Added HandleGetAETE
  26.         <55>     8/23/95    NP        1276287: Move constant kODAppShell.
  27.         <54>     8/22/95    eeh        1230007: use tempobjs
  28.         <53>     8/16/95    NP        1273600: FB: ShellSI is not ref-counted
  29.                                     correctly.
  30.         <52>     8/15/95    TÇ        1262179 FB: Shell calls BlockMove() in many
  31.                                     places
  32.         <51>     8/12/95    TÇ        1276806 Optimization: use kODFalse instead
  33.                                     of kODTrue in comparisons
  34.         <50>      8/8/95    jpa        Document file synchronization [1259401]
  35.         <49>      8/2/95    VL        1270320: Changed PlatformFile to
  36.                                     TempPlatformFile.
  37.         <48>     7/25/95    DM        #1270320: Memory leak fixes.
  38.         <47>     7/20/95    CC        1238642, 1244151: HandleHighLevelEvent:
  39.                                     Clear modifiers field of open document
  40.                                     Apple event to work around Edition mgr bug.
  41.         <46>      7/3/95    eeh        1264701: don't dispose tokens returned by
  42.                                     GetUserToken!
  43.         <45>     6/25/95    TÇ        1242642 BB: Turn on ODDebug warning if
  44.                                     refcount is wrong in
  45.                                     ODRefCntObjectsomUninit.
  46.         <44>     6/22/95    EL        #1261759: Do not call adjust menu when
  47.                                     processing high level event in the
  48.                                     background.
  49.         <43>      6/1/95    jpa        Added 2nd param to ExceptionAlert()
  50.                                     [1242839]
  51.         <42>     5/26/95    RR        #1251403: Multithreading naming support
  52.         <41>     5/21/95    NP        1248898: GetUserToken, ODDescToAEDesc, etc.
  53.                                     recipe change.
  54.         <40>     5/17/95    RR        #1250135/1250137/1250143 Getters increment
  55.                                     refcount
  56.         <39>     5/17/95    TÇ        1249144 BB: OpenDoc Shell doesn't handle
  57.                                     failures in the open documents event
  58.                                     correctly.
  59.         <38>     5/16/95    JP        1238991: Shell must supply an accessor for
  60.                                     file from null.
  61.         <36>     4/24/95    eeh        1240662: check keyODActivateEventCause,
  62.                                     call FakePrintMenuEvent
  63.         <35>     4/15/95    TÇ        #1216915 With help from JP: DR/BB:Trying to
  64.                                     open a document that is already open causes
  65.                                     an error.
  66.         <34>     4/14/95    TÇ        #1235279 BB: InfoUtil & StdTypIO functions
  67.                                     should take Environment* and SU* when
  68.                                     possible
  69.         <33>     4/10/95    TÇ        #1226675    Option-Close does not close all
  70.                                     Windows
  71.         <32>      4/7/95    eeh        1221297: HandleOpenPrintDocsEvent from ODOC
  72.                                     handler
  73.         <31>     3/31/95    TÇ        1204755 BB: Canceling save dialog when
  74.                                     Restart is chosen doesn't work correctly.
  75.                                     Works now. Even with shutdown.
  76.         <30>     3/13/95    NP        1223765: Add ODSession parameter to
  77.                                     InitSIHelper.
  78.         <29>      3/2/95    eeh        1214783: more cleanup
  79.         <28>     2/21/95    eeh        1214783: cleanup
  80.         <27>     2/20/95    TÇ        #1210979 BB: 5-$ Bugs need to be evaluated
  81.                                     and removed from Shell
  82.                                     #1221861 BB: Incomplete AOCE support needs
  83.                                     to be removed from OpenDoc
  84.         <26>     2/13/95    eeh        #1217393: fix GetHandlerFromAEVT
  85.         <25>      2/3/95    eeh        1217393: use new ODDesc etc.
  86.         <24>     1/27/95    NP        1213948: Fix event handlers.
  87.         <23>     1/25/95    eeh        1211798: make event handlers "pascal"
  88.         <22>     1/22/95    NP        GetUserToken et al signature changed
  89.                                     because of change to AE types.
  90.         <21>     1/16/95    eeh        1211798: use new method of dealing with
  91.                                     tokens (GetUserToken etc.)
  92.         <20>      1/9/95    NP        1194880: SemtIntf name changes.
  93.         <19>     12/5/94    jpa        Catch CFM errors opening new documents.
  94.                                     [1158966]
  95.         <18>    11/15/94    NP        1199847,1199053-Commented out some code
  96.                                     that uses an obsolete method and put a WARN
  97.                                     in. Fixed event handlers.
  98.         <17>    10/13/94    NP        1189812: Changed several callbacks to
  99.                                     pascal conventions.
  100.         <16>     9/29/94    RA        1189812: Mods for 68K build.
  101.         <15>     9/22/94    eeh        #1185445 save draft after attaching mailer.
  102.         <14>     9/15/94    NP        1186778: Changed token handling code.
  103.         <13>      9/8/94    eeh        #1185443: changes to HandleOpenDocsEvent.
  104.         <12>      9/2/94    eeh        moved mailer-specific stuff to RlShlMlr.cpp
  105.                                     in the process of fixing 1150934 and
  106.                                     1167302
  107.         <11>     8/29/94    TÇ        fixed header
  108.         <10>     8/29/94    TÇ        #1183567 StdTypIO routine implementation &
  109.                                     fixup
  110.          <9>     8/20/94    DO        1169445: now returning scripting size resource 
  111.          <8>     8/15/94    JBS        1181156: UI API Cleanup
  112.          <7>     8/13/94    NP        1180819-Adjusted calls to
  113.                                     InstallEventHandler.
  114.          <6>     7/27/94    eeh        install CoerceToFSSpec, but a version that
  115.                                     doesn't throw
  116.          <5>     7/26/94    eeh        don't install coercions (temp fix)
  117.          <4>     7/14/94    TÇ        fixed references to ASLMBILD and
  118.                                     uncommented calls to info functions
  119.          <3>     7/13/94    TÇ        removed some xmps
  120.          <2>     6/30/94    TÇ        uncommented references to GetNameResolver
  121.                                     etc.
  122.          <1>     6/30/94    TÇ        first checked in
  123.          <0>     6/29/94    SV        SOMverted
  124.         <12>     5/10/94    TÇ        #1162405 Removed explicit ASLM dependency
  125.                                     for using resources
  126.         <11>     4/12/94    eeh        bug #1154546: make HandleQuit close windows
  127.         <10>     3/28/94    CG        1153547: Renamed XMPSessn.h to XMPSessM.h
  128.          <9>     3/26/94    NP        1153509. Messaging not PowerPC ready.
  129.          <8>     3/25/94    eeh        Moved InstallEventHandlers() code into
  130.                                     InitAE() (no bug# yet)
  131.          <7>     3/25/94    eeh        bug #1153053: More changes for PPC
  132.                                     nativity.
  133.          <6>     3/24/94    eeh        bug #1153053: Changes for PPC nativity
  134.                                     (incomplete)
  135.          <5>     3/16/94    eeh        bug #1149649: HandleOpenDocsEvent now deals
  136.                                     with launches for OCE Reply
  137.          <4>      3/8/94    eeh        bug# 1149508: nuked installation of gdut
  138.                                     handler
  139.          <3>     2/24/94    TÇ        fix #1145435.  Save and Revert to Saved
  140.                                     menu items are now enabled properly (only
  141.                                     when there are changes to a draft)
  142.                                     brand new documents which have never been
  143.                                     saved are deleted when closed.  cleaned up
  144.                                     a few more comments.
  145.          <2>     2/15/94    TÇ        fix #1144029 and some cleanup
  146.         <19>      2/8/94    TÇ        Throw -> THROW & some code clean up
  147.         <18>      2/7/94    TÇ        fixes to compile with PPC Headers
  148.         <17>     1/17/94    NP        Semantic Events callbacks API changes.
  149.         <16>     1/15/94    RR        WinState.h->WinStat.h,
  150.                                     Dispatch.h->Disptch.h
  151.         <15>     1/13/94    eeh        removed dead code in GetAllAETEResources
  152.         <14>     1/11/94    eeh        backed out reading all the library files in
  153.                                     ASLM HandleGetAETE
  154.         <13>    12/17/93    eeh        fixed HandleGetAETE to work under ASLM.
  155.                                     (Reading all the library files will need to
  156.                                     be backed out.)
  157.         <12>     12/9/93    eeh        filled in Make, Save, Close and
  158.                                     CountElements -- partially
  159.         <11>    11/30/93    JA        Rearranged #includes for new "frame"
  160.                                     constant fix.
  161.         <10>    11/22/93    SS        Added typecasts for latest headers
  162.          <9>    11/15/93    eeh        Implemented Get&SetData (sorta), and added
  163.                                     stubs for the rest of the Core
  164.          <8>    11/12/93    CG        Added the HandleGetAETE AE handler and
  165.                                     GetAllAETEResources  -- not yet tested with
  166.                                     ASLM build!!!!
  167.          <7>    10/18/93    NP        Added pragma unused statements.
  168.          <6>    10/11/93    NP        Commented out installation of event
  169.                                     handler.
  170.          <5>     10/8/93    TÇ        comment out references to PROTOTYPEBUILD
  171.          <3>     9/23/93    TÇ        #include <SemtIntf.xh> so that it would
  172.                                     compile in the implementation
  173.          <2>      9/8/93    NP        blah blah blah.
  174.          <1>      9/7/93    NP        first checked in
  175.  
  176.     To Do:
  177.     In Progress:
  178.         
  179. */
  180.  
  181. #ifndef _PLFMDEF_
  182. #include <PlfmDef.h>
  183. #endif
  184.  
  185. #ifndef _SIHELPER_
  186. #include <SIHelper.h>
  187. #endif
  188.  
  189. #ifndef _ODPRCS_
  190. #include "ODPrcs.h"
  191. #endif
  192.  
  193. #ifndef SOM_ODSession_xh
  194. #include <ODSessn.xh>
  195. #endif
  196.  
  197. #ifndef _EXCEPT_
  198. #include <Except.h>
  199. #endif
  200.  
  201. #ifndef SOM_ShellSI_xh
  202. #include "ShellSI.xh"
  203. #endif
  204.  
  205. #ifndef _RLSHELL_
  206. #include "RlShell.h"
  207. #endif
  208.  
  209. #ifndef _SEUTILS_
  210. #include <SEUtils.h>
  211. #endif
  212.  
  213. #ifndef _SHPRPACC_
  214. #include "ShPrpAcc.h"
  215. #endif
  216.  
  217. #ifndef _SHLEVTHD_
  218. #include "ShlEvtHd.h"
  219. #endif
  220.  
  221. #ifndef _USERSRCM_
  222. #include <UseRsrcM.h>
  223. #endif
  224.  
  225. #ifndef _RLSHELL_
  226. #include "RlShell.h"
  227. #endif
  228.  
  229. #ifndef SOM_ODContainer_xh
  230. #include <ODCtr.xh>
  231. #endif
  232.  
  233. #ifndef _ODUTILS_
  234. #include <ODUtils.h>
  235. #endif
  236.  
  237. #ifndef _DOCUTILS_
  238. #include <DocUtils.h>
  239. #endif
  240.  
  241. #ifndef __ALIASES__
  242. #include <Aliases.h>
  243. #endif
  244.  
  245. #ifndef _PLFMFILE_
  246. #include <PlfmFile.h>
  247. #endif
  248.  
  249. #ifndef _ODDESUTL_
  250. #include <ODDesUtl.h>
  251. #endif
  252.  
  253. #ifndef SOM_ODDocument_xh
  254. #include <Document.xh>
  255. #endif
  256.  
  257. #ifndef SOM_ODNameResolver_xh
  258. #include <NamRslvr.xh>
  259. #endif
  260.  
  261. #ifndef SOM_ODWindowState_xh
  262. #include <WinStat.xh>
  263. #endif
  264.  
  265. #ifndef SOM_ODWindow_xh
  266. #include <Window.xh>
  267. #endif
  268.  
  269. #ifndef SOM_ODMessageInterface_xh
  270. #include <MssgIntf.xh>
  271. #endif
  272.  
  273. #ifndef SOM_ODDispatcher_xh
  274. #include <Disptch.xh>
  275. #endif
  276.  
  277. #ifndef SOM_ODWindowIterator_xh
  278. #include <WinIter.xh>
  279. #endif
  280.  
  281. #ifndef SOM_ODOSLToken_xh
  282. #include <ODOSLTkn.xh>
  283. #endif
  284.  
  285. #ifndef SOM_ODAppleEvent_xh
  286. #include <ODAplEvt.xh>
  287. #endif
  288.  
  289. #ifndef __ASREGISTRY__
  290. #include <ASRegistry.h>
  291. #endif
  292.  
  293. #ifndef __AEUserTermTypes__
  294. #include <AEUserTermTypes.h>
  295. #endif
  296.  
  297. #ifndef __APPLEEVENTS__
  298. #include <AppleEvents.h>
  299. #endif
  300.  
  301. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  302. #include "ODRgstry.xh"
  303. #endif
  304.  
  305. #ifndef __RESOURCES__
  306. #include <Resources.h>
  307. #endif
  308.  
  309. #ifndef _ODDEBUG_
  310. #include "ODDebug.h"
  311. #endif
  312.  
  313. #ifndef _TEMPOBJ_
  314. #include "TempObj.h"
  315. #endif
  316.  
  317. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  318. #include <StdDefs.xh>
  319. #endif
  320.  
  321. #pragma segment ShellEvt
  322.  
  323. //==============================================================================
  324. // Constants
  325. //==============================================================================
  326.  
  327. #define STATICBUILD
  328.  
  329. const DescType kShellPropAccessor         = 0x73706163;    // 'spac';
  330. const DescType kShellSelfPropAccessor    = 0x7368656C;    // 'shel';
  331.  
  332. const DescType kShellEventHandler = 'shev';
  333.  
  334. //==============================================================================
  335. // Function Prototypes
  336. //==============================================================================
  337.  
  338. //void    CreateUniqueTmpFolderForFile(ODFileSpec* result, Str63 fileName);
  339.  
  340. #define HANDLER_PARAMS                                                     \
  341.     ODPart* thePart,                                                     \
  342.     ODAppleEvent* message,                                             \
  343.      ODAppleEvent* reply,                                                 \
  344.     ODSLong handlerRefcon
  345.  
  346. // pascal ODError HandleClone(HANDLER_PARAMS);
  347. pascal ODError HandleClose(HANDLER_PARAMS);
  348. // pascal ODError HandleCountEl(HANDLER_PARAMS);
  349. // pascal ODError HandleMake(HANDLER_PARAMS);
  350. // pascal ODError HandleDelete(HANDLER_PARAMS);
  351. // pascal ODError HandleDoExist(HANDLER_PARAMS);
  352. // pascal ODError HandleGetClsInfo(HANDLER_PARAMS);
  353. // pascal ODError HandleGetData(HANDLER_PARAMS);
  354. // pascal ODError HandleGetDataSz(HANDLER_PARAMS);
  355. // pascal ODError HandleGetEvnInfo(HANDLER_PARAMS);
  356. // pascal ODError HandleMove(HANDLER_PARAMS);
  357. // pascal ODError HandleOpen(HANDLER_PARAMS);
  358. // pascal ODError HandlePrint(HANDLER_PARAMS);
  359. pascal ODError HandleSave(HANDLER_PARAMS);
  360. // pascal ODError HandleSetData(HANDLER_PARAMS);
  361. pascal ODError HandleODActivate(HANDLER_PARAMS);
  362.  
  363. pascal ODError HandleGetAETE(HANDLER_PARAMS);
  364.  
  365. #undef HANDLER_PARAMS
  366.                 
  367. pascal ODError GetFileFromNULL(    ODPart*                part,
  368.                                 DescType            desiredClass,
  369.                                 ODOSLToken*            container,
  370.                                 DescType            containerClass,
  371.                                 DescType            form,
  372.                                 ODDesc*                selectionData,
  373.                                 ODOSLToken*            value,
  374.                                 ODSLong                refCon);
  375.  
  376.  
  377. ShellEventHandler* GetHandlerFromAEVT(AppleEvent* theAppleEvent,
  378.         RealShell* self);
  379. void GetDirectParam(RealShell* self, AppleEvent* theAppleEvent,
  380.         AEDesc* evtDp);
  381.  
  382. //==============================================================================
  383. // RealShell
  384. //==============================================================================
  385.  
  386. //-------------------------------------------------------------------------------------
  387. // Apple Event Support
  388. //-------------------------------------------------------------------------------------
  389.  
  390.  
  391. void RealShell::InitAE()
  392. {
  393.     Environment* ev = fEV;
  394.  
  395.     ShellSI* shellSemtInterface = new ShellSI;
  396.     THROW_IF_NULL(shellSemtInterface);
  397.     fSIHelper = new SIHelper;
  398.     fSIHelper->InitSIHelper(fSession, shellSemtInterface);
  399.     shellSemtInterface->InitCPlusSemanticInterface(ev, kODAppShell, fSIHelper,
  400.                                                 fSession);
  401.     fSession->SetShellSemtInterface(ev, shellSemtInterface);
  402.     shellSemtInterface->Release(ev); // SetShellSemtInterface acquires.
  403.  
  404.     ODObjectAccessorUPP newAccessor = 
  405.             NewODObjectAccessorProc( GetFileFromNULL );
  406.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallObjectAccessor( cFile, 
  407.                                         typeNull, newAccessor, (ODSLong)fSession );
  408.                                 
  409.     ODEventHandlerUPP newHandler = 
  410.             NewODEventHandlerProc( RealShell::HandleOpenAppEvent );
  411.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  412.                                 kAEOpenApplication,
  413.                                 newHandler,
  414.                                 (long)this);
  415.                                 
  416.     newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
  417.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  418.                                 kAEOpenDocuments,
  419.                                 newHandler,
  420.                                 (long)this);
  421.                                 
  422.     newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
  423.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  424.                                 kAEPrintDocuments,
  425.                                 newHandler ,
  426.                                 (long)this);
  427.                                 
  428.     newHandler = NewODEventHandlerProc( RealShell::HandleQuitEvent );
  429.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  430.                                 kAEQuitApplication,
  431.                                 newHandler ,
  432.                                 (long)this);
  433.  
  434.     newHandler = NewODEventHandlerProc( RealShell::HandleLaunchFailedEvent );
  435.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
  436.                                 kCFMLaunchFailedEventClass,
  437.                                 kCFMLaunchFailedEventID,
  438.                                 newHandler ,
  439.                                 (long)this);
  440.  
  441.     newHandler = NewODEventHandlerProc( RealShell::HandleODActivate );
  442.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
  443.                                 kAEOpenDocSuite,
  444.                                 kODActivateEvent,
  445.                                 newHandler ,
  446.                                 (long)this);
  447.  
  448.     ODCoercionHandlerUPP fsSpecCoerceHdlr =
  449.             NewODDescCoercionHandlerProc( RealShell::CoerceToFSSpec );
  450.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler( typeAlias, typeFSS,
  451.             fsSpecCoerceHdlr, (long)this, kODTrue );
  452.                                 
  453. //    this->InstallObjectAccessors(shellSemtInterface);
  454.     
  455. /*
  456. ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler(typeChar, typeFSS,
  457.                                 (XMPCoercionHandler)Pathname2FSSpec, kNoRefCon,
  458.                                 kFromTypeIsNotDesc );
  459. */
  460.  
  461.     ODEventHandlerUPP eventHandlerUPP;
  462.     
  463. #ifdef TO_BE_DELETED
  464.     eventHandlerUPP = NewODEventHandlerProc(HandleClone);
  465.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClone,
  466.             eventHandlerUPP, (ODSLong)this);
  467. #endif /* TO_BE_DELETED */
  468.     
  469.     eventHandlerUPP = NewODEventHandlerProc(HandleClose);
  470.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClose,
  471.             eventHandlerUPP, (ODSLong)this);
  472.     
  473. #ifdef TO_BE_DELETED
  474.     eventHandlerUPP = NewODEventHandlerProc(HandleCountEl);
  475.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECountElements,
  476.             eventHandlerUPP, (ODSLong)this);
  477.  
  478.     eventHandlerUPP = NewODEventHandlerProc(HandleMake);
  479.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECreateElement,
  480.             eventHandlerUPP, (ODSLong)this);
  481.     
  482.     eventHandlerUPP = NewODEventHandlerProc(HandleDelete);
  483.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDelete,
  484.             eventHandlerUPP, (ODSLong)this);
  485.         
  486.     eventHandlerUPP = NewODEventHandlerProc(HandleDoExist);
  487.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDoObjectsExist,
  488.             eventHandlerUPP, (ODSLong)this);
  489.         
  490.     eventHandlerUPP = NewODEventHandlerProc(HandleGetClsInfo);
  491.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetClassInfo,
  492.             eventHandlerUPP, (ODSLong)this);
  493.         
  494.     eventHandlerUPP = NewODEventHandlerProc(HandleGetData);
  495.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetData,
  496.             eventHandlerUPP, (ODSLong)this);
  497.         
  498.     eventHandlerUPP = NewODEventHandlerProc(HandleGetDataSz);
  499.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetDataSize,
  500.             eventHandlerUPP, (ODSLong)this);
  501.         
  502.     eventHandlerUPP = NewODEventHandlerProc(HandleGetEvnInfo);
  503.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetEventInfo,
  504.             eventHandlerUPP, (ODSLong)this);
  505.         
  506.     eventHandlerUPP = NewODEventHandlerProc(HandleMove);
  507.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEMove,
  508.             eventHandlerUPP, (ODSLong)this);
  509.         
  510.     eventHandlerUPP = NewODEventHandlerProc(HandleOpen);
  511.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEOpen,
  512.             eventHandlerUPP, (ODSLong)this);
  513.         
  514.     eventHandlerUPP = NewODEventHandlerProc(HandlePrint);
  515.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEPrint,
  516.             eventHandlerUPP, (ODSLong)this);
  517. #endif /* TO_BE_DELETED */
  518.         
  519.     eventHandlerUPP = NewODEventHandlerProc(HandleSave);
  520.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESave,
  521.             eventHandlerUPP, (ODSLong)this);
  522.         
  523. #ifdef TO_BE_DELETED
  524.     eventHandlerUPP = NewODEventHandlerProc(HandleSetData);
  525.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESetData,
  526.             eventHandlerUPP, (ODSLong)this);
  527. #endif /* TO_BE_DELETED */
  528.  
  529. //#ifndef STATICBUILD
  530.     // Just let AS get the resource directly if not ASLM.  In fact, we
  531.     // probably don't need this even in that case.
  532.     eventHandlerUPP = NewODEventHandlerProc(HandleGetAETE);
  533.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAEOpenDocSuite, kGetAETE,
  534.                                                 eventHandlerUPP,
  535.                                                 (ODSLong)this);
  536. //#endif /* STATICBUILD */
  537.  
  538. }
  539.  
  540.  
  541. void RealShell::HandleHighLevelEvent(ODEventData* event)
  542. {
  543.     Environment* ev = fEV;
  544.     ProcessSerialNumber myPSN,frontPSN;
  545.     ODBoolean active;
  546.     (void)GetCurrentProcess(&myPSN);
  547.     (void)GetFrontProcess(&frontPSN);
  548.     (void)SameProcess(&myPSN,&frontPSN,&active);
  549.     if (active)
  550.         this->UpdateMenus();
  551.  
  552.     if ( ((AEEventClass) event->message == 'aevt') && (*(AEEventID *) &(event->where) == 'odoc') )
  553.     {
  554.         // If the open document event was sent by the edition manager, the modifiers field
  555.         // of the event will be garbage.  This can cause AEProcessAppleEvent to return an error
  556.         // instead of calling one of our event handlers.
  557.         // We work around this by clearing the modifiers field.  Note that clearing the field
  558.         // is not correct if the event is larger than 64K; we take the chance that an 'odoc'
  559.         // event won't be this large. [cc 7/19/95] [Radar #1261856]
  560.         event->modifiers = 0;
  561.     }
  562.  
  563.     ODBoolean succeeded = fSession->GetMessageInterface(ev)->ProcessSemanticEvent(ev, event);
  564. }
  565.  
  566.  
  567. pascal ODError RealShell::HandleOpenAppEvent(ODPart* part,
  568.                                         ODAppleEvent* message,
  569.                                         ODAppleEvent* reply,
  570.                                         long refCon)
  571. {
  572. ODUnused(part);
  573. ODUnused(message);
  574. ODUnused(reply);
  575.  
  576.     RealShell*    self = (RealShell*)refCon;
  577.     Environment* ev = self->fEV;
  578.     ODError    error = noErr;
  579.  
  580.     TRY
  581.  
  582.     // Create a new stationery document on OAPP
  583. /*
  584.     self->OpenFile(self->New());
  585.     self->Open();
  586. */
  587.         self->New();
  588.         self->GetSession()->GetDispatcher(ev)->Exit(ev);    
  589.     
  590.     CATCH_ALL
  591.         error = ErrorCode();
  592.         self->GetSession()->GetDispatcher(ev)->Exit(ev);
  593.         self->SetAEError(error);
  594.     ENDTRY
  595.  
  596.     return error;
  597. }
  598.  
  599. void RealShell::FakePrintMenuEvent()
  600. {
  601.     Environment* ev = fEV;
  602.     ODDispatcher* dispatcher = this->GetSession()->GetDispatcher(ev);
  603.     
  604.     ODMenuID menu;
  605.     ODMenuItemID menuItem;
  606.     TempODMenuBar baseMenuBar = this->fWindowState->AcquireBaseMenuBar(ev);
  607.     baseMenuBar->GetMenuAndItem(ev, kODCommandPrint, &menu, &menuItem );
  608.     
  609.     ODEventData event;
  610.     event.message = (menu<<16) | menuItem;
  611.     event.what = kODEvtMenu;
  612.     // zero the rest of the fields
  613.     WASSERT( sizeof(Point) == sizeof(long) );    // this is gross but
  614.     *(long*)&event.where = 0L;
  615.     event.when = 0L;
  616.     event.modifiers = 0;
  617.     dispatcher->Dispatch(ev, &event);
  618. }
  619.  
  620. pascal ODError RealShell::HandleOpenPrintDocsEvent(    ODPart* part,
  621.                                             ODAppleEvent* message,
  622.                                             ODAppleEvent* reply,
  623.                                             long refCon)
  624. {
  625. ODUnused(part);
  626. ODUnused(reply);
  627.  
  628.     RealShell*    self = (RealShell*)refCon;
  629.     Environment* ev = self->fEV;
  630.     ODSession* session = self->GetSession();
  631.     ODVolatile(session);
  632.     
  633.     ODFileSpec        aFile;
  634.  
  635.     long        itemsInList;
  636.     AEKeyword    aDocKeyword;
  637.     AEDesc        aFileSpecDesc;
  638.     OSErr        err;
  639.     ODError    error = noErr;
  640.     AppleEvent    realMessage;
  641.     DescType eventID;
  642.     DescType ignoreType;
  643.     Size ignoreActual;
  644.  
  645.     TRY
  646.     // get list of documents
  647.     realMessage.dataHandle = kODNULL;
  648.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  649.     AEDesc docList;
  650.     THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyDirectObject, typeAEList,
  651.             &docList));
  652.     TempAEDesc tmpDesc(&docList);
  653.     THROW_IF_ERROR( AEGetAttributePtr( &realMessage, keyEventIDAttr, typeType,
  654.             &ignoreType, &eventID, sizeof(eventID), &ignoreActual ));
  655.     ODBoolean isPrint = eventID == kAEPrintDocuments;
  656.     if (MissingParams(&realMessage))
  657.         THROW( errAEParamMissed );
  658.     
  659.     // count number of documents to open
  660.     THROW_IF_ERROR( AECountItems(&docList, &itemsInList ));
  661.     WASSERT( itemsInList == 1 );
  662.  
  663.     ODSLong indexStart;
  664.     TempPlatformFile file = kODNULL;
  665.  
  666.     if (ODGetFirstOpenDocument(ev, session)==kODNULL)
  667.     {
  668.         // Get FSSpec for first (hopefully only) document
  669.         THROW_IF_ERROR(err = AEGetNthDesc(&docList, 1, typeFSS, 
  670.                                             &aDocKeyword, &aFileSpecDesc));
  671.         ODBlockMove(*(aFileSpecDesc.dataHandle), (Ptr)&aFile, sizeof(aFile));
  672.         AEDisposeDesc(&aFileSpecDesc);
  673.         indexStart = 2;
  674.         file = new PlatformFile;
  675.         file->Specify(&aFile);
  676.     } else {
  677.          indexStart = 1;
  678.     }
  679.  
  680.     // spawn shell processes to handle extra documents
  681.     for (ODSLong index = indexStart; index <= itemsInList; index++)
  682.     {
  683.         ODFileSpec        extraFile;
  684.         // ONLY HANDLING FSSPECS HERE!
  685.         err = AEGetNthDesc(&docList, index, typeFSS, &aDocKeyword,
  686.                                 &aFileSpecDesc);
  687.         // We'll handle tokens here...
  688.  
  689.         if (err == errAECoercionFail)
  690.         {
  691.             AEDesc    coerceDesc = NULL_DESCRIPTOR_DEFINITION;
  692.             ODOSLToken* tmpWrapper = new ODOSLToken();
  693.             THROW_IF_NULL(tmpWrapper);
  694.             TempODObject tempObj(tmpWrapper);
  695.             tmpWrapper->InitODOSLToken(ev);
  696.  
  697.             TRY
  698.                 GetDirectParam(self, &realMessage, &coerceDesc);
  699.                 TempAEDesc tmpCD( &coerceDesc );
  700.                 THROW_IF_ERROR( AEDescToODDesc(&coerceDesc, tmpWrapper ) );
  701.                 ODDesc* myToken;
  702.                 ODNameResolver*    resolver = session->GetNameResolver(ev);
  703.                 myToken = resolver->GetUserToken(ev, tmpWrapper);
  704.                 AEDisposeDesc( &coerceDesc );
  705.                 THROW_IF_ERROR( ODDescToAEDesc(myToken, &coerceDesc) );
  706.                 THROW_IF_ERROR( AECoerceDesc(&coerceDesc, typeFSS, &aFileSpecDesc) );
  707. //                ODDeleteObject(tmpWrapper);
  708.                 err = noErr;
  709.             CATCH_ALL
  710. //                ODDeleteObject(tmpWrapper);
  711.                 // There was an error coercing to FSSpec and we couldn't deal.
  712.                 // Should we do anything? Do we care?
  713.                 // RERAISE;
  714.             ENDTRY
  715.         }
  716.         if (!err)
  717.             ODBlockMove(*(aFileSpecDesc.dataHandle), (Ptr)&extraFile, sizeof(extraFile));
  718.             
  719.         AEDisposeDesc(&aFileSpecDesc);
  720.         
  721.         if (!err) 
  722.         {
  723.             TempPlatformFile file = new PlatformFile();
  724.             file->Specify(&extraFile);
  725.             self->OpenAnotherFile(file );
  726.             // ODDeleteObject(file); // temp auto-deletes
  727.         }
  728.         else
  729.             ; 
  730.             // There was an error with open/printing an additional document
  731.             // Should we do anything? Do we care?
  732.     }
  733.  
  734. //    AEDisposeDesc(&docList);
  735.     if (file!=kODNULL) {
  736.         
  737.         self->OpenFile(file);
  738.                 
  739.         if ( isPrint )    // make it print, then quit
  740.         {
  741.             self->FakePrintMenuEvent();
  742.             if (ODCloseDocument(ev, session, ODGetFirstOpenDocument(ev, session)))
  743.                 session->GetDispatcher(ev)->Exit(ev);
  744.         }
  745.     }
  746.  
  747.     CATCH_ALL
  748.         error = ErrorCode();
  749.         session->GetDispatcher(ev)->Exit(ev);
  750.         self->SetAEError(error);
  751.     ENDTRY
  752.     ODDisposeAppleEvent( &realMessage );
  753.  
  754.     return error;
  755. }    // HandleOpenPrintDocsEvent()
  756.  
  757. ////////////////////////////////////////////////////////////////////////////////
  758. //
  759. //        HandleQuitEvent
  760. //
  761. ////////////////////////////////////////////////////////////////////////////////
  762.  
  763. pascal ODError RealShell::HandleQuitEvent(    ODPart* /*part*/,
  764.                                         ODAppleEvent* /*message*/,
  765.                                         ODAppleEvent* /*reply*/,
  766.                                         long refCon)
  767. {
  768.     ODError    error = noErr;
  769.     RealShell*    self = (RealShell*)refCon;
  770.     Environment* ev = self->fEV;
  771.     ODSession* session = self->GetSession();
  772. //    AEDesc theFile = { typeNull, kODNULL };
  773.  
  774.     TRY
  775.         // In OpenDoc the 'QUIT' event means CloseDocument.
  776.         // $$$$$ WILL CONTINUE TO ASK EVEN IF YOU CANCEL THE SAVE CHANGES? DIALOG.
  777.         
  778.         RealShell* self = (RealShell*)refCon;
  779.         ODDocument* document = kODNULL;
  780.         while ((document = ODGetFirstOpenDocument(ev, session)) != kODNULL)
  781.             self->CloseDocument(ODGetActiveDocument(ev, self->GetSession()), kAEAsk);
  782.         session->GetDispatcher(ev)->Exit(ev);
  783.     
  784.     CATCH_ALL
  785.         error = ErrorCode();
  786.     ENDTRY
  787.  
  788.     return error;
  789. }    // HandleQuitEvent()
  790.  
  791.  
  792. ////////////////////////////////////////////////////////////////////////////////
  793. //
  794. //        HandleLaunchFailedEvent
  795. //
  796. ////////////////////////////////////////////////////////////////////////////////
  797.  
  798. pascal ODError RealShell::HandleLaunchFailedEvent(    ODPart* part,
  799.                                         ODAppleEvent* message,
  800.                                         ODAppleEvent* reply,
  801.                                         long refCon)
  802. {
  803.     ODUnused(part);
  804.     ODUnused(reply);
  805.     
  806.     long launchErr;
  807.     ProcessSerialNumber psn;
  808.     Str255 appName, libName;
  809.     AppleEvent realMessage;
  810.  
  811.     THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
  812.     
  813.     //<eeh> any chance this can throw???
  814.     GetLaunchFailedParams(&realMessage, launchErr,&psn,appName,libName);
  815.     ODDisposeAppleEvent(&realMessage);
  816.  
  817.     RealShell *shell = (RealShell*)refCon;
  818.     shell->LaunchFailed(launchErr,psn,appName,libName);
  819.     return noErr;
  820. }
  821.  
  822.  
  823. void
  824. RealShell::LaunchFailed( ODSLong launchErr, const ProcessSerialNumber &psn,
  825.                          Str255 appName, Str255 libName )
  826. {
  827.     if( psn.lowLongOfPSN != kNoProcess ) {
  828.         Boolean result;
  829.         if( SameProcess(&psn,&fLastNewDocPSN,&result) == noErr && result != kODFalse ) {
  830.             // This is a new document we just created & launched; better delete it.
  831.             OSErr err= FSpDelete(&fLastNewDocSpec);
  832.             if( err )
  833.                 WARN("Error %d trying to delete new document",err);
  834.             fLastNewDocPSN.lowLongOfPSN = kNoProcess;
  835.             fLastNewDocSpec.name[0] = '\0';
  836.         }
  837.     }
  838.     
  839.     this->ExceptionAlert(launchErr,kODNULL);
  840. }
  841.  
  842.  
  843. ////////////////////////////////////////////////////////////////////////////////
  844. //
  845. //        HandleODActivateEvent
  846. //
  847. ////////////////////////////////////////////////////////////////////////////////
  848.  
  849. pascal ODError RealShell::HandleODActivate( ODPart* thePart, ODAppleEvent* message,
  850.         ODAppleEvent* reply, ODSLong handlerRefcon )
  851. {
  852.     ODUnused(thePart);
  853.     ODUnused(reply);
  854.     
  855.     ODError result = noErr;
  856.  
  857.     RealShell*    self = (RealShell*)handlerRefcon;
  858.     
  859.     ODFileSpec    fileSpec;
  860.     AppleEvent    realMessage;
  861.     DescType    unused1;
  862.     Size        unused2;
  863.     ODBoolean    wasPrintEvent = kODFalse;
  864.     ODBoolean    notAlreadyOpen = kODFalse;
  865.     boolean        quitAfterPrint = kODFalse;
  866.     TempODDraft draftToBringForward = kODNULL;
  867.  
  868.     realMessage.dataHandle = NULL;
  869.     TRY
  870.         THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
  871.         THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyDirectObject, typeFSS, 
  872.                 &unused1, (Ptr)&fileSpec, sizeof(fileSpec), &unused2));
  873.         DescType spawningEventID;
  874.         OSErr err = AEGetParamPtr(&realMessage, keyODActivateEventCause,
  875.                 typeType,  &unused1, (Ptr)&spawningEventID,
  876.                 sizeof(spawningEventID), &unused2 );
  877.         if ( err == noErr )
  878.             wasPrintEvent = spawningEventID == kAEPrintDocuments;
  879.         // else drop the error: id not present is ok.
  880.  
  881.         err = AEGetParamPtr( &realMessage, keyODRefnumFromResource,
  882.                 typeBoolean,  &unused1, (Ptr)&quitAfterPrint,
  883.                 sizeof(quitAfterPrint), &unused2 );
  884.         if ( err != noErr )
  885.             quitAfterPrint = kODFalse;
  886.  
  887.     CATCH_ALL
  888.         result = ErrorCode();
  889.     ENDTRY
  890.     ODDisposeAppleEvent(&realMessage);
  891.  
  892.     Environment* ev = self->fEV;
  893.     ODSession* session = self->GetSession();
  894.  
  895.     if ( result == noErr )
  896.     {
  897.         ODULong refNumCount, i;
  898.         ODSShort* refNums = kODNULL;
  899.         GetLocalPaths(&fileSpec, kDataFork, &refNumCount, &refNums);
  900.     
  901.         if (refNumCount != 0)
  902.         {
  903.             for ( i=0; i<refNumCount; ++i)
  904.             {
  905.                 ODDocument* doc = ODGetOpenDocumentFromRefNum(ev,
  906.                         session, refNums[i]);
  907.                 if ( doc != kODNULL )
  908.                 {
  909.                     draftToBringForward = ODGetTempDraftFromOpenDocument( ev,
  910.                             session, doc );
  911.                             
  912.                     if (draftToBringForward)
  913.                         draftToBringForward->Acquire(ev); // balance destructor of TempRef
  914.                     else
  915.                         draftToBringForward = 
  916.                             doc->AcquireDraft(ev,kODDPReadOnly,0,kODNULL,kODPosTop,kODFalse);
  917.                             
  918.                     break;        // exit for loop
  919.                 }
  920.             }
  921.         
  922.             if (refNums)
  923.                 DisposePtr((Ptr)refNums);
  924.         }
  925.         else        // *if* this process is supposed to handle this event at
  926.         {            // all, the ODActivate must have come because of a resource
  927.                     // fork.
  928.             short resRefNum = CurResFile();
  929.             if ( refNums != kODNULL )
  930.             {
  931.                 DisposePtr( (Ptr)refNums );
  932.                 refNums = kODNULL;
  933.             }
  934.             GetLocalPaths( &fileSpec, kResourceFork, &refNumCount, &refNums );
  935.             for ( i=0; i<refNumCount; ++i )
  936.             {
  937.                 if ( refNums[i] == resRefNum )    // it belongs in this process
  938.                 {
  939.                     TempPlatformFile file = new PlatformFile;
  940.                     file->Specify( &fileSpec );
  941.                     draftToBringForward = ODOpenFileDocument( ev, session, file,
  942.                         kODDPSharedWrite );
  943.  
  944.                     self->InstallShellPlugIns(draftToBringForward);
  945.                     notAlreadyOpen = kODTrue;
  946.                     break;
  947.                 }
  948.             }
  949.             if( refNums != kODNULL )
  950.                 DisposePtr( (Ptr)refNums );
  951.         }
  952.     }
  953.     
  954.     if ( draftToBringForward != kODNULL )
  955.     {
  956.         ProcessSerialNumber psn;
  957.         GetCurrentProcess(&psn);
  958.         SetFrontProcess(&psn);
  959.  
  960.         ODOpenDraft( ev, session, draftToBringForward );
  961.         if ( notAlreadyOpen )
  962.         {
  963.             // the plugin may have patched these....
  964.             self->fDispatcher = session->GetDispatcher(ev);
  965.             self->fWindowState = session->GetWindowState(ev);
  966.         }
  967.         if ( wasPrintEvent )
  968.         {
  969.             self->FakePrintMenuEvent();
  970.             if ( quitAfterPrint )
  971.             {
  972.                 // need to release draft's refcount *before* calling
  973.                 // ODCloseDocument (or check with Tantek to see if
  974.                 // assertion in ODCloseDocument can be removed.
  975.                 ODDocument* doc = draftToBringForward->GetDocument(ev);
  976.                 draftToBringForward->Release(ev);
  977.                 draftToBringForward = kODNULL;    // prevent another release by the TempRef
  978.                 ODBoolean wasLastDoc = ODCloseDocument( ev, session, doc );
  979.                 WASSERT( !wasLastDoc ); 
  980.             }
  981.         }
  982.     }
  983.  
  984.     return result;        // usually should be eventNotHandled?
  985. }    // HandleODActivate
  986.  
  987.  
  988. ////////////////////////////////////////////////////////////////////////////////
  989. //
  990. //        CoerceToFSSpec
  991. //
  992. ////////////////////////////////////////////////////////////////////////////////
  993.  
  994.  
  995. pascal ODError RealShell::CoerceToFSSpec( ODPart* thePart, ODDesc* theAEDesc,
  996.         DescType toType, ODSLong handlerRefCon, ODDesc* result )
  997. {
  998.     ODUnused(thePart);
  999.     RealShell*    self = (RealShell*)handlerRefCon;
  1000.  
  1001.     if (self->fAlreadyInCoercion)
  1002.         return errAECoercionFail;
  1003.     else
  1004.         self->fAlreadyInCoercion = kODTrue;
  1005.     ODError    error = noErr;
  1006.  
  1007.     TRY
  1008.         AEDesc    realInDesc;
  1009.         THROW_IF_ERROR( ODDescToAEDesc(theAEDesc, &realInDesc));
  1010.         TempAEDesc tmpDesc(&realInDesc);
  1011.         if (realInDesc.descriptorType == typeAlias)
  1012.         {
  1013.             // use the built-in coercion first
  1014.             AEDesc tmpResult;
  1015.             error = AECoerceDesc( &realInDesc, toType, &tmpResult );
  1016.     
  1017.             if ( error == noErr )
  1018.             {
  1019.                 TempAEDesc tmpDesc(&tmpResult);
  1020.                 THROW_IF_ERROR( AEDescToODDesc( &tmpResult, result ));
  1021.             }
  1022.         }
  1023.  
  1024.     CATCH_ALL
  1025.         error = ErrorCode();
  1026.     ENDTRY
  1027.  
  1028.     self->fAlreadyInCoercion = kODFalse;
  1029.     return error;
  1030. }    // CoerceToFSSpec()
  1031.  
  1032. //----------------------------------------------------------------------------------------
  1033. // RealShell::SetAEError 
  1034. //----------------------------------------------------------------------------------------
  1035.  
  1036. void RealShell::SetAEError(ODError error)
  1037. {
  1038.     fErrorFromOpenEvents = error;
  1039. }
  1040.  
  1041. //----------------------------------------------------------------------------------------
  1042. // RealShell::GetAEError 
  1043. //----------------------------------------------------------------------------------------
  1044.  
  1045. ODError RealShell::GetAEError()
  1046. {
  1047.     return fErrorFromOpenEvents;
  1048. }
  1049.  
  1050. //==============================================================================
  1051. // Functions
  1052. //==============================================================================
  1053.  
  1054. //------------------------------------------------------------------------------
  1055. // HandleGetAETE
  1056. //------------------------------------------------------------------------------
  1057.  
  1058.  
  1059. pascal ODError HandleGetAETE(ODPart*        thePart,
  1060.                 ODAppleEvent*    theAppleEvent,
  1061.                 ODAppleEvent*    reply,
  1062.                 ODSLong    handlerRefcon)
  1063. {
  1064. ODUnused(thePart);
  1065. ODUnused(handlerRefcon);    
  1066.  
  1067.     AEDesc        theAETE = NULL_DESCRIPTOR_DEFINITION;
  1068.     DescType    returnedType;
  1069.     ODSize        actualSize;
  1070.     ODSLong        languageCode;
  1071.     ODError        result;
  1072.     ODError        error = noErr;
  1073.     
  1074.     AppleEvent realMessage, realReply;
  1075.     realMessage.dataHandle = realReply.dataHandle = NULL;
  1076.  
  1077.     TRY
  1078.         THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
  1079.         THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1080.  
  1081.         result = AEGetParamPtr(&realMessage, keyDirectObject, typeLongInteger,
  1082.                                &returnedType, (Ptr)&languageCode, sizeof(languageCode),
  1083.                                (Size *)&actualSize);
  1084.         ODDisposeAppleEvent(&realMessage);
  1085.         THROW_IF_ERROR(result);
  1086.         
  1087.         TRY
  1088.             CUsingLibraryResources    ref;
  1089.             
  1090.             theAETE.dataHandle = Get1Resource(typeAETE, (short)languageCode);
  1091.             if (theAETE.dataHandle)
  1092.             {
  1093.                 theAETE.descriptorType = typeAETE;
  1094.                 result = AEPutParamDesc(&realReply, keyAEResult, &theAETE);
  1095.                 ReleaseResource(theAETE.dataHandle);
  1096.                 THROW_IF_ERROR(result);
  1097.             }
  1098.         CATCH_ALL
  1099.             error = ErrorCode();
  1100.         ENDTRY
  1101.                         
  1102.         THROW_IF_ERROR(error);
  1103.         
  1104.         THROW_IF_ERROR(AEDescToODDesc(&realReply, reply));
  1105.     CATCH_ALL
  1106.         error = ErrorCode();
  1107.     ENDTRY
  1108.     AEDisposeDesc(&realReply);
  1109.  
  1110.     return error;
  1111. }    // HandleGetAETE()
  1112.  
  1113.  
  1114. //------------------------------------------------------------------------------
  1115. // GetFileFromNULL
  1116. //------------------------------------------------------------------------------
  1117.  
  1118. pascal ODError GetFileFromNULL(    ODPart*                part,
  1119.                                 DescType            desiredClass,
  1120.                                 ODOSLToken*            container,
  1121.                                 DescType            containerClass,
  1122.                                 DescType            form,
  1123.                                 ODDesc*                selectionData,
  1124.                                 ODOSLToken*            value,
  1125.                                 ODSLong                refCon)
  1126. {
  1127.     Environment*            ev = somGetGlobalEnvironment();
  1128.     ODSession*                session = (ODSession*)refCon;
  1129.     ODNameResolver*            resolver = session->GetNameResolver(ev);
  1130.     ODError                    error = noErr;
  1131.     AEDesc                    aeAlias, tmp;
  1132.     char                    state;
  1133.  
  1134.     TRY
  1135.         // get the selectionData and coerce it into an fsspec
  1136.         THROW_IF_ERROR(ODDescToAEDesc(selectionData, &tmp));
  1137.         TempAEDesc tmpDesc(&tmp);
  1138.         state = HGetState(tmp.dataHandle);
  1139.         HLock(tmp.dataHandle);
  1140.         THROW_IF_ERROR(NewAliasMinimalFromFullPath(GetHandleSize(tmp.dataHandle),
  1141.                 *tmp.dataHandle, "\p", "\p",
  1142.                 (AliasHandle*)&aeAlias.dataHandle ));
  1143.         HSetState(tmp.dataHandle, state);
  1144.         aeAlias.descriptorType = typeAlias;
  1145.         TempAEDesc tmpDesc2(&aeAlias);
  1146.         UpdateUserToken(ev, resolver, value, &aeAlias);
  1147.     CATCH_ALL
  1148.         error = ErrorCode();
  1149.     ENDTRY
  1150.  
  1151.     return error;
  1152. }    //    GetFileFromNULL
  1153.  
  1154. //------------------------------------------------------------------------------
  1155. // HandleClone
  1156. //------------------------------------------------------------------------------
  1157.  
  1158. #ifdef TO_BE_DELETED
  1159. pascal ODError HandleClone( ODPart* thePart, ODAppleEvent* theAppleEvent,
  1160.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1161. {
  1162.     ODUnused(thePart);
  1163.  
  1164.     ODError    error = noErr;
  1165.  
  1166.     AppleEvent realMessage, realReply;
  1167.     THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
  1168.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1169.  
  1170.     TRY
  1171.  
  1172.         ShellEventHandler* handlerObj = GetHandlerFromAEVT( &realMessage,
  1173.                 (RealShell*)handlerRefcon );
  1174.     
  1175.         AEDesc cloneLocation;
  1176.         THROW_IF_ERROR( AEGetParamDesc( &realMessage, keyAEInsertHere, 
  1177.                 typeInsertionLoc, &cloneLocation ) );
  1178.     
  1179.         AEDesc replyDp;
  1180.         handlerObj->Clone( &cloneLocation, &replyDp );
  1181.         delete handlerObj;
  1182.     
  1183.         THROW_IF_ERROR( AEPutParamDesc( &realReply, keyDirectObject, &replyDp ) );
  1184.  
  1185.     CATCH_ALL
  1186.         error = ErrorCode();
  1187.     ENDTRY
  1188.  
  1189.     return error;
  1190. }    // HandleClone()
  1191. #endif /* TO_BE_DELETED */
  1192.  
  1193. //------------------------------------------------------------------------------
  1194. // HandleClose
  1195. //------------------------------------------------------------------------------
  1196.  
  1197. pascal ODError HandleClose( ODPart* thePart, ODAppleEvent* message,
  1198.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1199. {
  1200.     ODUnused(thePart);
  1201.     ODUnused(reply);
  1202.  
  1203.     AEDesc theFile;
  1204.     ODError    error = noErr;
  1205.  
  1206.     AppleEvent realMessage, realReply;
  1207.     // can't use TempAEDescs for these because they don't call
  1208.     // ODDisposeAppleEvent
  1209.     realMessage.dataHandle = realReply.dataHandle = NULL;
  1210.  
  1211.     TRY
  1212.         THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1213.         THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1214.         OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
  1215.         TempAEDesc tmpDesc(&theFile);
  1216.         ThrowIfNotAbsent(err);
  1217.     
  1218.         DescType saveOptions = kAEAsk, typeFound;
  1219.         Size actualSize;
  1220.         err = AEGetParamPtr(&realMessage, keyAESaveOptions, typeEnumeration,
  1221.                 &typeFound, (Ptr)&saveOptions, sizeof(saveOptions), &actualSize);
  1222.         ThrowIfNotAbsent(err);
  1223.     
  1224.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1225.                 (RealShell*)handlerRefcon);
  1226.         handlerObj->Close(&theFile, saveOptions);
  1227.         delete handlerObj;
  1228.  
  1229.     CATCH_ALL
  1230.         error = ErrorCode();
  1231.     ENDTRY
  1232.  
  1233.     ODDisposeAppleEvent(&realMessage);
  1234.     ODDisposeAppleEvent(&realReply);
  1235.     return error;
  1236. }
  1237.  
  1238. //------------------------------------------------------------------------------
  1239. // HandleCountEl
  1240. //------------------------------------------------------------------------------
  1241.  
  1242. #ifdef TO_BE_DELETED
  1243. pascal ODError HandleCountEl(ODPart* thePart, ODAppleEvent* message, ODAppleEvent* reply,
  1244.         ODSLong handlerRefcon)
  1245. {
  1246.     ODUnused(thePart);
  1247.  
  1248.     ODError    error = noErr;
  1249.  
  1250.     AppleEvent realMessage, realReply;
  1251.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1252.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1253.  
  1254.     TRY
  1255.  
  1256.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1257.                 (RealShell*)handlerRefcon);
  1258.     
  1259.         DescType elemClass, typeFound;
  1260.         Size actualSize;
  1261.         THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
  1262.                 &typeFound, (Ptr)&elemClass, sizeof(elemClass), &actualSize));
  1263.     
  1264.         AEDesc replyDp;
  1265.         handlerObj->CountElements(elemClass, &replyDp);
  1266.         delete handlerObj;
  1267.     
  1268.         THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
  1269.  
  1270.     CATCH_ALL
  1271.         error = ErrorCode();
  1272.     ENDTRY
  1273.  
  1274.     return error;
  1275. }
  1276. #endif /* TO_BE_DELETED */
  1277.  
  1278. //------------------------------------------------------------------------------
  1279. // HandleMake
  1280. //------------------------------------------------------------------------------
  1281.  
  1282. #ifdef TO_BE_DELETED
  1283. pascal ODError HandleMake(ODPart* thePart, ODAppleEvent* message,
  1284.         ODAppleEvent* reply, ODSLong handlerRefcon)
  1285. {
  1286.     ODUnused(thePart);
  1287.     ODUnused(handlerRefcon);
  1288.     ODUnused(reply);
  1289.  
  1290.     DescType newObjClass, typeFound;
  1291.     Size actualSize;
  1292.     AEDesc insertHere, newObjectName;
  1293.     OSErr err;
  1294.     ODError    error = noErr;
  1295.  
  1296.     AppleEvent realMessage, realReply;
  1297.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1298.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1299.  
  1300.     TRY
  1301.     
  1302.         THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
  1303.                 &typeFound, (Ptr)&newObjClass, sizeof(newObjClass), &actualSize));
  1304.         THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEInsertHere,
  1305.                 typeInsertionLoc, &insertHere));
  1306.         err = AEGetParamDesc(&realMessage, 'type', typeChar, &newObjectName);
  1307.         if (err && (err != errAEDescNotFound))
  1308.             THROW(err);
  1309.     
  1310.         err = AEGetParamDesc(&realMessage, 'subj', typeChar, &newObjectName);
  1311.         if (err && (err != errAEDescNotFound))
  1312.             THROW(err);
  1313.  
  1314.     CATCH_ALL
  1315.         error = ErrorCode();
  1316.     ENDTRY
  1317.  
  1318.     return error;
  1319. }
  1320. #endif /* TO_BE_DELETED */
  1321.  
  1322. //------------------------------------------------------------------------------
  1323. // HandleDelete
  1324. //------------------------------------------------------------------------------
  1325.  
  1326. #ifdef TO_BE_DELETED
  1327. pascal ODError HandleDelete( ODPart* thePart, ODAppleEvent* message,
  1328.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1329. {
  1330.     ODUnused(thePart);
  1331.     ODUnused(reply);
  1332.     ODError error = noErr;
  1333.  
  1334.     AppleEvent realMessage, realReply;
  1335.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1336.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1337.  
  1338.     TRY
  1339.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1340.                 (RealShell*)handlerRefcon);
  1341.         handlerObj->Delete();
  1342.         delete handlerObj;
  1343.  
  1344.     CATCH_ALL
  1345.         error = ErrorCode();
  1346.     ENDTRY
  1347.  
  1348.     return error;
  1349. }
  1350. #endif /* TO_BE_DELETED */
  1351.  
  1352. //------------------------------------------------------------------------------
  1353. // HandleDoExist
  1354. //------------------------------------------------------------------------------
  1355.  
  1356. #ifdef TO_BE_DELETED
  1357. pascal ODError HandleDoExist( ODPart* thePart, ODAppleEvent* message,
  1358.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1359. {
  1360.     ODUnused(thePart);
  1361.     ODUnused(message);
  1362.     ODUnused(reply);
  1363.     ODUnused(handlerRefcon);
  1364.     return errAEEventNotHandled;
  1365. }
  1366. #endif /* TO_BE_DELETED */
  1367.  
  1368. //------------------------------------------------------------------------------
  1369. // HandleGetClsInfo
  1370. //------------------------------------------------------------------------------
  1371.  
  1372. #ifdef TO_BE_DELETED
  1373. pascal ODError HandleGetClsInfo( ODPart* thePart, ODAppleEvent* message,
  1374.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1375. {
  1376.     ODUnused(thePart);
  1377.     ODUnused(message);
  1378.     ODUnused(reply);
  1379.     ODUnused(handlerRefcon);
  1380.     return errAEEventNotHandled;
  1381. }
  1382. #endif /* TO_BE_DELETED */
  1383.  
  1384. //------------------------------------------------------------------------------
  1385. // HandleGetData
  1386. //------------------------------------------------------------------------------
  1387.  
  1388. #ifdef TO_BE_DELETED
  1389. pascal ODError HandleGetData( ODPart* thePart, ODAppleEvent* message,
  1390.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1391. {
  1392.     ODUnused(thePart);
  1393.     ODUnused(handlerRefcon);
  1394.  
  1395.     AEDesc evtDp;
  1396.     AEDesc replyDp;
  1397.     ODError    error = noErr;
  1398.  
  1399.     RealShell* self = (RealShell*)handlerRefcon;
  1400.     Environment* ev = somGetGlobalEnvironment();
  1401.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1402.  
  1403.     AppleEvent realMessage, realReply;
  1404.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1405.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1406.  
  1407. //    ODOSLToken* tmpWrapper = kODNULL;
  1408.     TRY
  1409.  
  1410.         replyDp.dataHandle = NULL;
  1411.         evtDp.dataHandle = NULL;
  1412.     
  1413.         GetDirectParam((RealShell*)handlerRefcon, &realMessage,
  1414.                 &evtDp);
  1415.         ODOSLToken* tmpWrapper = new ODOSLToken();
  1416.         THROW_IF_NULL(tmpWrapper);
  1417.         TempODObject tempObj(tmpWrapper);
  1418.         tmpWrapper->InitODOSLToken(ev);
  1419.         THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
  1420.  
  1421.         if( !resolver->IsODToken(ev, tmpWrapper) )
  1422.             THROW(errAEEventNotHandled);
  1423.         ODDesc* myTokenODDesc;
  1424.         myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
  1425.         AEDesc myToken;
  1426.         THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
  1427. //        ODDeleteObject(myTokenODDesc);
  1428.         
  1429.         switch( myToken.descriptorType )
  1430.         {
  1431.             case kShellSelfPropAccessor :
  1432.             case kShellPropAccessor :
  1433.                 ShellPropAccessor* accessorObj =
  1434.                         FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
  1435.                         ShellPropAccessor*);
  1436.                 accessorObj->GetPropertyData(&replyDp);
  1437.                 delete accessorObj;
  1438.                 break;
  1439.     
  1440.             default :
  1441.                 THROW(errAEEventNotHandled);
  1442.                 break;
  1443.         }
  1444.  
  1445.         THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
  1446.         THROW_IF_ERROR( AEDescToODDesc(&realReply, reply ) );
  1447.         
  1448.         AEDisposeDesc(&evtDp);
  1449.         AEDisposeDesc(&replyDp);
  1450.  
  1451.     CATCH_ALL
  1452.         error = ErrorCode();
  1453.     ENDTRY
  1454.  
  1455. //    ODDeleteObject(tmpWrapper);
  1456.     return error;
  1457. }    // HandleGetData();
  1458. #endif /* TO_BE_DELETED */
  1459.  
  1460.  
  1461. //------------------------------------------------------------------------------
  1462. // HandleGetDataSz
  1463. //------------------------------------------------------------------------------
  1464.  
  1465. #ifdef TO_BE_DELETED
  1466. pascal ODError HandleGetDataSz( ODPart* thePart, ODAppleEvent* message,
  1467.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1468. {
  1469.     ODUnused(thePart);
  1470.     ODUnused(message);
  1471.     ODUnused(reply);
  1472.     ODUnused(handlerRefcon);
  1473.     return errAEEventNotHandled;
  1474. }
  1475. #endif /* TO_BE_DELETED */
  1476.  
  1477. //------------------------------------------------------------------------------
  1478. // HandleGetEvnInfo
  1479. //------------------------------------------------------------------------------
  1480.  
  1481. #ifdef TO_BE_DELETED
  1482. pascal ODError HandleGetEvnInfo( ODPart* thePart, ODAppleEvent* message,
  1483.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1484. {
  1485.     ODUnused(thePart);
  1486.     ODUnused(message);
  1487.     ODUnused(reply);
  1488.     ODUnused(handlerRefcon);
  1489.     return errAEEventNotHandled;
  1490. }
  1491. #endif /* TO_BE_DELETED */
  1492.  
  1493. //------------------------------------------------------------------------------
  1494. // HandleMove
  1495. //------------------------------------------------------------------------------
  1496.  
  1497. #ifdef TO_BE_DELETED
  1498. pascal ODError HandleMove( ODPart* thePart, ODAppleEvent* message,
  1499.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1500. {
  1501.     ODUnused(thePart);
  1502.     ODUnused(message);
  1503.     ODUnused(reply);
  1504.     ODUnused(handlerRefcon);
  1505.     return errAEEventNotHandled;
  1506. }
  1507. #endif /* TO_BE_DELETED */
  1508.  
  1509. //------------------------------------------------------------------------------
  1510. // HandleOpen
  1511. //------------------------------------------------------------------------------
  1512.  
  1513. #ifdef TO_BE_DELETED
  1514. pascal ODError HandleOpen( ODPart* thePart, ODAppleEvent* message,
  1515.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1516. {
  1517.     ODUnused(thePart);
  1518.     ODUnused(message);
  1519.     ODUnused(reply);
  1520.     ODUnused(handlerRefcon);
  1521.     return errAEEventNotHandled;
  1522. }
  1523. #endif /* TO_BE_DELETED */
  1524.  
  1525. //------------------------------------------------------------------------------
  1526. // HandlePrint
  1527. //------------------------------------------------------------------------------
  1528.  
  1529. #ifdef TO_BE_DELETED
  1530. pascal ODError HandlePrint( ODPart* thePart, ODAppleEvent* message,
  1531.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1532. {
  1533.     ODUnused(thePart);
  1534.     ODUnused(message);
  1535.     ODUnused(reply);
  1536.     ODUnused(handlerRefcon);
  1537.     return errAEEventNotHandled;
  1538. }
  1539. #endif /* TO_BE_DELETED */
  1540.  
  1541. //------------------------------------------------------------------------------
  1542. // HandleSave
  1543. //------------------------------------------------------------------------------
  1544.  
  1545. pascal ODError HandleSave( ODPart* thePart, ODAppleEvent* message,
  1546.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1547. {
  1548.     ODUnused(thePart);
  1549.     ODUnused(reply);
  1550.     AEDesc theFile;
  1551.     ODError    error = noErr;
  1552.  
  1553.     AppleEvent realMessage, realReply;
  1554.     realMessage.dataHandle = realReply.dataHandle = NULL;
  1555.  
  1556.     TRY
  1557.         THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1558.         THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1559.  
  1560.         OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
  1561.         ThrowIfNotAbsent(err);
  1562.     
  1563.     //    keyAEFileType
  1564.     
  1565.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1566.                 (RealShell*)handlerRefcon);
  1567.         handlerObj->Save(&theFile /*,&theFileType*/);
  1568.         delete handlerObj;
  1569.  
  1570.     CATCH_ALL
  1571.         error = ErrorCode();
  1572.     ENDTRY
  1573.  
  1574.     ODDisposeAppleEvent(&realMessage);
  1575.     ODDisposeAppleEvent(&realReply);
  1576.     return error;
  1577. }    // HandleSave()
  1578.  
  1579. //------------------------------------------------------------------------------
  1580. // HandleSetData
  1581. //------------------------------------------------------------------------------
  1582.  
  1583. #ifdef TO_BE_DELETED
  1584. pascal ODError HandleSetData( ODPart* thePart, ODAppleEvent* message,
  1585.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1586. {
  1587.     ODUnused(thePart);
  1588.     ODUnused(reply);
  1589.  
  1590.     AEDesc dataDesc;
  1591.     ODError    error = noErr;
  1592.  
  1593.     RealShell* self = (RealShell*)handlerRefcon;
  1594.     Environment* ev = somGetGlobalEnvironment();
  1595.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1596.  
  1597.     AppleEvent realMessage, realReply;
  1598.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1599. //    THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1600.  
  1601. //    ODOSLToken* tmpWrapper = kODNULL;
  1602.     TRY
  1603.  
  1604.         dataDesc.dataHandle = NULL;
  1605.         THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEData, typeWildCard,
  1606.                 &dataDesc));
  1607.     
  1608.         AEDesc evtDp;
  1609.         GetDirectParam( self, &realMessage, &evtDp );
  1610.         AEDisposeDesc( &realMessage );
  1611.     
  1612.         ODOSLToken* tmpWrapper = new ODOSLToken();
  1613.         THROW_IF_NULL(tmpWrapper);
  1614.         TempODObject tempObj(tmpWrapper);
  1615.         tmpWrapper->InitODOSLToken(ev);
  1616.         THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
  1617.     
  1618.         if( !resolver->IsODToken(ev, tmpWrapper) )
  1619.             THROW(errAEEventNotHandled);
  1620.         ODDesc* myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
  1621.         AEDesc myToken;
  1622.         THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken) );
  1623.     
  1624.         switch( myToken.descriptorType )
  1625.         {
  1626.             case kShellSelfPropAccessor :
  1627.             case kShellPropAccessor :
  1628.                 ShellPropAccessor* accessorObj =
  1629.                         FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
  1630.                         ShellPropAccessor*);
  1631.                 accessorObj->SetPropertyData(&dataDesc);
  1632.                 delete accessorObj;
  1633.                 break;
  1634.             default :
  1635.                 THROW(errAEEventNotHandled);
  1636.                 break;
  1637.         }
  1638.     
  1639.         AEDisposeDesc(&myToken);    
  1640.         AEDisposeDesc(&dataDesc);    
  1641.  
  1642.     CATCH_ALL
  1643.         AEDisposeDesc(&dataDesc);    
  1644.         error = ErrorCode();
  1645.     ENDTRY
  1646.  
  1647. //    ODDeleteObject(tmpWrapper);
  1648.     return error;
  1649. }    // HandleSetData()
  1650. #endif /* TO_BE_DELETED */
  1651.  
  1652.  
  1653. //******************************************************************************
  1654. // Utility functions
  1655. //******************************************************************************
  1656.  
  1657. ShellEventHandler* GetHandlerFromAEVT(AppleEvent* message,
  1658.         RealShell* self)
  1659. {
  1660.     Environment* ev = somGetGlobalEnvironment();
  1661.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1662.  
  1663.     AEDesc evtDp;
  1664.     THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
  1665.             &evtDp));
  1666.     TempAEDesc tmpdesc(&evtDp);
  1667.  
  1668.     ShellEventHandler* handlerObj;
  1669.     if (evtDp.descriptorType == typeNull)
  1670.     {
  1671.         handlerObj = new ShellEventHandler(typeNull, (ODObject*)self,
  1672.                 (ODSLong)self);
  1673.     }
  1674.     else
  1675.     {
  1676.         ODOSLToken* tmpWrapper = new ODOSLToken();
  1677.         THROW_IF_NULL(tmpWrapper);
  1678.         TempODObject tempObj(tmpWrapper);
  1679.         tmpWrapper->InitODOSLToken(ev);
  1680.         THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
  1681.     
  1682.         if( !resolver->IsODToken(ev, tmpWrapper) )
  1683.             THROW(errAEEventNotHandled);
  1684.         ODDesc* myTokenODDesc;
  1685.         myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
  1686.         AEDesc myToken;
  1687.         THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
  1688.  
  1689.         handlerObj = FIRSTBYTESFROMHANDLE(myToken.dataHandle,
  1690.                 ShellEventHandler*);
  1691.         AEDisposeDesc(&myToken);
  1692. //        ODDeleteObject(tmpWrapper);
  1693.     }
  1694.  
  1695. //    AEDisposeDesc(&evtDp);
  1696.     return handlerObj;
  1697. }    // GetHandlerFromAEVT()
  1698.  
  1699.  
  1700. //------------------------------------------------------------------------------
  1701. // GetDirectParam
  1702. //------------------------------------------------------------------------------
  1703.  
  1704. // THIS FUNCTION NEEDS A FIXIN' TO USE THE NEW WAY OF DOING DEFAULT ACCESSORS.
  1705.  
  1706. void GetDirectParam(RealShell* self, AppleEvent* message,
  1707.         AEDesc* evtDp)
  1708. {
  1709.     Environment* ev = somGetGlobalEnvironment();
  1710.     AEDesc localDP;
  1711.     THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
  1712.             &localDP));
  1713.  
  1714.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1715.  
  1716.     ODOSLToken* tmpWrapper = new ODOSLToken();
  1717.     THROW_IF_NULL(tmpWrapper);
  1718.     TempODObject tempObj(tmpWrapper);
  1719.     tmpWrapper->InitODOSLToken(ev);
  1720.     THROW_IF_ERROR( AEDescToODDesc(&localDP, tmpWrapper ) );
  1721.  
  1722.     ODBoolean istoken = resolver->IsODToken(ev, tmpWrapper) ;
  1723. //    ODDeleteObject(tmpWrapper);
  1724.     if ( istoken )
  1725.     {
  1726.         *evtDp = localDP;
  1727.     }
  1728.     else
  1729.     {
  1730.         WARN("RlShlEv.cpp: GetDirectParam. Found a non-token.  About to throw.");
  1731.         THROW( errAEEventNotHandled );
  1732.     }
  1733. }    // GetDirectParam()
  1734.